Return to doc.sitecore.com

Valid for Sitecore 5.2, 5.1.1
  Create a Method Rendering
Prev Next

Method Renderings are .NET methods which accept no parameter and return a string which are registered as Renderings with Sitecore.

First create the class containing the method in Microsoft® Visual Studio .NET.  Ensure the assembly (DLL) containing the new class exists in the /bin directory under the Sitecore site’s document root.

Currently Method Renderings cannot be added to a Layout or Sublayout using drag-and-drop.  If the Method Rendering will only be bound to a Layout or Sublayout statically, simply edit the Layout or Sublayout which will contain the Method Rendering and add a line such as the following:

<sc:method runat="server" methodname="Method" classname="custom.Sample" assemblyname="custom" />

(replacing methodname, classname and assemblyname with appropriate values).

To bind the Method Rendering to a Placeholder in a Layout or Sublayout, the Method must be registered in Sitecore as a Rendering:

Unfortunately this wizards has not been completed:

  1. In content editor, change the first step of the treecrumb to Layout.
  2. Expand the Renderings node and select an existing Rendering.
  3. From the New menu select Add from Template.
  4. Select System, Layout, Renderings and Method Rendering.
  5. Move the new Rendering from under the existing Rendering to the main Renderings so that it is not a child of another Rendering.
  6. Complete the properties of the new Rendering (additional details are available at http://sdn.sitecore.net/Articles/4,-d-,3/Method%20Renderings.html):
    1. Assembly: the name of the assembly containing the class containing the method (the file name of the DLL without the .dll extension)
    2. Class: the fully qualified class containing the method (namespace.classname)
    3. Method: the name of the method to be invoked when the Rendering is processed
  7. Associate the new Rendering with a Placeholder key for Templates and/or Items just as you would do with a Sublayout or XSL Rendering.

As a shortcut for registering additional Method Renderings, duplicate an existing Method Rendering and change its properties (starting at step 6 above).


Prev Next